﻿@model MvcCmsProjectTracker.ViewModels.TicketNotificationViewModel
<div id="notifications">
    @if (Model.TicketNotifications.Count > 0)
    { 
        <table>
            <tr>
                <th>
                    User Name
                </th>
                <th>
                </th>
            </tr>
            @foreach (var item in Model.TicketNotifications)
            { 
                <tr>
                    <td>
                        @item.UserName
                    </td>
                    <td>
                        @if (item.UserName == HttpContext.Current.User.Identity.Name)
                        {
                            @Ajax.ActionLink("Delete", "DeleteNotification", new { id = item.NotificationID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "notifications", OnFailure = "handleFailure", Confirm = "Are you sure you want to delete this notification?", OnSuccess = "styleControls" })
                        }
                    </td>
                </tr>
            }
        </table>
    }
    @{ 
        var hasNotification = (from n in Model.TicketNotifications
                               where n.UserName == HttpContext.Current.User.Identity.Name
                               select n).Count();
        if (hasNotification == 0)
        {
        @Ajax.ActionLink("Add Notification", "AddNotification", new { id = Model.TicketID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "notifications", OnFailure = "handleFailure" }, new { @class = "button" })
        }
    }
    <br />
    @Html.Partial("ControlsProjectTracker/Message", Model)
</div>
